package com.newhopegroup.useractiontrack.core.authentication.service;

import com.google.common.base.Preconditions;
import com.newhopegroup.useractiontrack.api.userAction.vo.UserActionResultVo;
import com.newhopegroup.useractiontrack.core.authentication.dao.UserActionDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by liutt on 15-7-2.
 */
@Service
public class UserActionService {
    private final Logger logger = LoggerFactory.getLogger(UserActionService.class);
    @Resource
    private UserActionDao userActionDao;

    public List<UserActionResultVo> querybydate(Date startDate, Date endDate) {
        Preconditions.checkNotNull(startDate, "startDate must not be null");
        Preconditions.checkNotNull(endDate, "endDate must not be null");

        List<UserActionResultVo> userActionResults = new ArrayList<UserActionResultVo>();
        List<String> uuids = userActionDao.queryuuidbydate(startDate, endDate);
        logger.info("uuids:[{}]", uuids);
        for (String uuid : uuids) {
            Integer count = userActionDao.querycountbyuuid(uuid, startDate, endDate);
            logger.info("uuid,count:[{}]", uuid, count);
            UserActionResultVo userActionResult = new UserActionResultVo();
            userActionResult.setUuid(uuid);
            userActionResult.setCount(count);
            logger.info("userActionResult:[{}]", userActionResult);
            userActionResults.add(userActionResult);
            logger.info("userActionResults:[{}]", userActionResults);
        }
        return userActionResults;
    }

}
